Skip to content

fix(retro-metrics): count Swift/XCTest tests, exclude generated output and prose specs - #2809

Open
snig-17 wants to merge 1 commit into
garrytan:mainfrom
snig-17:fix/swift-test-detection
Open

fix(retro-metrics): count Swift/XCTest tests, exclude generated output and prose specs#2809
snig-17 wants to merge 1 commit into
garrytan:mainfrom
snig-17:fix/swift-test-detection

Conversation

@snig-17

@snig-17 snig-17 commented Sep 5, 2026

Copy link
Copy Markdown

Running /retro on a SwiftUI project with 243 tests reported a 0% test ratio and a focus score of 97% (.build/). Three related blind spots in gstack-retro-metrics, each fixable independently.

1. XCTest naming is invisible

is_test matched lowercase test/|tests?/|spec/|__tests__/ directories and .test./.spec./_test./_spec. suffixes.

Swift uses AppTests/StoreTests.swift — capital T, no separator before Tests — which matches neither. Worth noting that even SwiftPM's standard Tests/ directory missed, because the directory pattern is case-sensitive. The same gap hits C# (Foo.Tests/FooTests.cs).

Added: capitalized [Tt]ests?/ / [Ss]pecs?/ directories, and a CamelCase filename form FooTests.swift / FooTest.cs. The capital letter is load-bearing, so Latest.swift and Contests.swift do not match.

2. Generated output counted as authored code

A committed build directory dominated FOCUS_SCORE (97% .build/ rather than the real 60% Nourish/), and .build/Logs/Test/ counted as test LOC — build output inflating the test ratio.

is_generated now drops .build/, build/, dist/, out/, target/, vendor/, node_modules/, DerivedData/, .next/, .nuxt/, __pycache__/, coverage/ before any counter is touched.

3. "spec" is overloaded

docs/specs/*.md are written specifications, not RSpec tests. On this project they were adding ~1,800 lines of prose to TEST_INSERTIONS. Prose is never test code, whatever directory it sits in, so is_test now returns 0 for markdown/text and anything under docs/.

Also

TEST_FILES_CHANGED used the narrow suffix-only pattern instead of is_test, so it read 0 while 21 test files had changed in the window.

Verification

Metric Before After Hand count
TEST_INSERTIONS 0 2423 2423
TEST_FILES_CHANGED 0 21 21
TEST_FILES_TOTAL 0 21 21
FOCUS_SCORE 97% (.build/) 60% (Nourish/)

All 11 existing contract tests still pass. Adds a 12th with its own fixture repo covering all three cases, so the shared fixture's deterministic aggregates are untouched.

🤖 Generated with Claude Code

…t and prose

Three related blind spots in test detection, all found running /retro on a
SwiftUI project with 243 tests that reported a 0% test ratio.

1. XCTest naming. is_test matched lowercase test/|tests?/|spec/ dirs and
   .test./_test. suffixes. Swift uses AppTests/StoreTests.swift, which
   matches neither. Even SwiftPM's standard Tests/ directory missed,
   because the pattern is case-sensitive. Same blind spot hits C#
   (Foo.Tests/FooTests.cs).

2. Generated output counted as authored code. A committed build directory
   put FOCUS_SCORE at 97% (.build/) instead of the real 60% (Nourish/),
   and .build/Logs/Test/ counted as test LOC. is_generated now drops
   build output before any counter is touched.

3. "spec" is overloaded. docs/specs/*.md are written specifications, not
   RSpec tests, and were adding thousands of prose lines to TEST_INSERTIONS.
   Prose is never test code, whatever directory it sits in.

TEST_FILES_CHANGED also used the narrow suffix-only pattern rather than
is_test, so it read 0 while 21 test files had changed.

On the project that surfaced this, TEST_INSERTIONS and TEST_FILES_CHANGED
now match a hand count exactly (2423 and 21).

Adds a regression test with its own fixture repo, leaving the shared
fixture's deterministic aggregates untouched.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@trunk-io

trunk-io Bot commented Sep 5, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant